package com.neteast.androidclient.contact.activity;

import java.util.ArrayList;
import java.util.Arrays;
import com.neteast.androidclient.contact.R;
import com.neteast.androidclient.contact.domain.Contact;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.RadioButton;
/**
 * 主界面，包含两个按钮，点击按钮，装载对应的activity
 * @author tiangh
 * 2012-3-12 下午5:22:58
 */
public class MainActivity extends ActivityGroup implements OnCheckedChangeListener {
    private LinearLayout container;
    public static ArrayList<String> phoneTypes=new ArrayList<String>();
	public static ArrayList<String> emailTypes=new ArrayList<String>();
	public static ArrayList<String> imTypes=new ArrayList<String>();
	public static ArrayList<String> locationTypes=new ArrayList<String>();
	
	public static ArrayList<String> cloudGroups=new ArrayList<String>();
	public static ArrayList<String> contactGroups=new ArrayList<String>();
	public static ArrayList<Contact> cloudFriends=new ArrayList<Contact>();
	public static ArrayList<Contact> contactFriends=new ArrayList<Contact>();
	private RadioButton btnContact;
	private RadioButton btnMe;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.main);
        init();
    }

	private void init() {
		container = (LinearLayout) findViewById(R.id.container);
		btnContact = (RadioButton) findViewById(R.id.btn_contact);
		btnMe = (RadioButton) findViewById(R.id.btn_me);
		btnContact.setOnCheckedChangeListener(this);
		btnMe.setOnCheckedChangeListener(this);
		
		phoneTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.phone_types)));
		emailTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.email_types)));
		imTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.im_types)));
		locationTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.location_types)));
		container.addView(getLocalActivityManager().startActivity("contact", 
				new Intent(this,ContactActivity.class)
						.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
						.getDecorView());
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		phoneTypes.clear();
		emailTypes.clear();
		imTypes.clear();
		locationTypes.clear();
	}

	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			switch (buttonView.getId()) {
			case R.id.btn_contact:
				container.removeAllViews();
				container.addView(getLocalActivityManager().startActivity("contact", 
						new Intent(this,ContactActivity.class)
								.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
								.getDecorView());
				break;
			case R.id.btn_me:
				container.removeAllViews();
				container.addView(getLocalActivityManager().startActivity("me", 
						new Intent(this,MeActivity.class)
								.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
								.getDecorView());	
				break;
			}
		}
	}
}